#include <voice.h>
#include <STC8G_H_GPIO.h>
#include <STC8G_H_UART.h>
#include <lcd.h>

void VOICE_Init(void) {
    // 首先设置gpio为准双向口
    GPIO_InitTypeDef initTypeDef;
    initTypeDef.Mode = GPIO_PullUp;
    initTypeDef.Pin = GPIO_Pin_1 | GPIO_Pin_0;
    GPIO_Inilize(GPIO_P1, &initTypeDef); // 设置P0.4、P0.5为漏极开路(实验箱加了上拉电阻到3.3V)
    // 初始化串口2

    COMx_InitDefine		COMx_InitStructure;					//结构定义
	COMx_InitStructure.UART_Mode      = UART_8bit_BRTx;		//模式,       UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
	COMx_InitStructure.UART_BRT_Use   = BRT_Timer2;			//选择波特率发生器,   BRT_Timer1, BRT_Timer2 (注意: 串口2固定使用BRT_Timer2)
	COMx_InitStructure.UART_BaudRate  = 9600;			//波特率, 一般 110 ~ 115200
	COMx_InitStructure.UART_RxEnable  = DISABLE;				//接收允许,   ENABLE或DISABLE
	COMx_InitStructure.BaudRateDouble = DISABLE;			//波特率加倍, ENABLE或DISABLE
	COMx_InitStructure.UART_Interrupt = ENABLE;				//中断允许,   ENABLE或DISABLE
	COMx_InitStructure.UART_Priority  = Priority_0;			//指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
	COMx_InitStructure.UART_P_SW      = UART2_SW_P10_P11;	//切换端口,   UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17,UART1_SW_P43_P44
	UART_Configuration(UART2, &COMx_InitStructure);		    //初始化串口1 UART1,UART2,UART3,UART4
}

void spk(u8 num) {
    // 首先发送起始标志
    TX2_write2buff(0X7E);
    // 发送命令
    TX2_write2buff(0X13);
    // 发送包序列先发高位再发低位
    TX2_write2buff(0X00);
    TX2_write2buff(0X02);
    // 发送数据
    TX2_write2buff(0X00);
    TX2_write2buff(0x03);
    // 发送结束
    TX2_write2buff(0XEF);
}

